using System.Diagnostics;
using System.IO;

namespace SZipHandler
{
    public class SzRun
    {
        private readonly string _exeFile;


        public SzRun(string exeFile)
        {
            _exeFile = exeFile;
        }

        public string RunProcess(string fileName, string outFolder)
        {
            if (!File.Exists(_exeFile))
                return string.Format("Application not Exists ({0})", _exeFile);

            if (!File.Exists(fileName))
                return string.Format("Archive not Exists ({0})", fileName);

            var process = new Process();
            process.StartInfo = new ProcessStartInfo(_exeFile, string.Format("x -o\"{0}\" \"{1}\" -y", outFolder, fileName));
            process.StartInfo.CreateNoWindow = true;
            process.StartInfo.UseShellExecute = false;
            process.StartInfo.RedirectStandardOutput = true;
            process.Start();

            process.WaitForExit();

            return process.StandardOutput.ReadToEnd();
        }
    }
}